package com.freeman.cement.controller;

import com.freeman.cement.annotation.NeedRole;
import com.freeman.cement.entity.Camera;
import com.freeman.cement.entity.CameraGroup;
import com.freeman.cement.entity.CameraSquare;
import com.freeman.cement.entity.ResponseResult;
import com.freeman.cement.service.CameraService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

//摄像头
@RestController
@RequestMapping("/camera")
@CrossOrigin    //允许跨域访问
public class CameraController {

    @Resource
    private CameraService service;

    //region 202211

    /**
     * 通过区域分页查询摄像头列表
     * @param regionIndexCode
     * @param pageNo
     * @param pageSize
     * @return
     */
    @RequestMapping(value = "/selectCameraByRegion", method = RequestMethod.POST)
    public ResponseResult selectCameraByRegion(@RequestParam String regionIndexCode, Integer isEnabled, @RequestParam int pageNo, @RequestParam int pageSize){
        return service.selectCameraByRegion(regionIndexCode, isEnabled, pageNo, pageSize);
    }

    /**
     * 通过工段、值班室、专业查找摄像头
     * @param Camera
     * @param pageNo
     * @param pageSize
     * @return
     */
    @RequestMapping(value = "/selectCamera", method = RequestMethod.POST)
    public ResponseResult selectCamera(Camera Camera, @RequestParam int pageNo, @RequestParam int pageSize){
        return service.selectCamera(Camera, pageNo, pageSize);
    }

    /**
     * 通过摄像头名称和CameraIndexCode的关键字检索摄像头，如果keyword为空的话检索全部摄像头
     * @param keyword
     * @param pageNo
     * @param pageSize
     * @return
     */
    @RequestMapping(value = "/selectCameraByKeyword", method = RequestMethod.POST)
    public ResponseResult selectCameraByKeyword(String keyword, @RequestParam int pageNo, @RequestParam int pageSize){
        return service.selectCameraByKeyword(keyword, pageNo, pageSize);
    }

    /**
     * 查询摄像头列表，后台管理摄像头列表使用，和移动端检索摄像头列表使用
     * @param deptId
     * @param worksectionId
     * @param deptDutyId
     * @param keyword
     * @param pageNo
     * @param pageSize
     * @return
     */
    @RequestMapping(value = "/selectCameras", method = RequestMethod.POST)
    public ResponseResult selectCameras(Integer deptId, Integer worksectionId, Integer deptDutyId,
                                        Integer isEnabled, Integer isRecvEnabled,
                                        String keyword, @RequestParam int pageNo, @RequestParam int pageSize){
        return service.selectCameras(deptId, worksectionId, deptDutyId, isEnabled, isRecvEnabled, keyword, pageNo, pageSize);
    }

    /**
     * 获取摄像头详情，通过cameraIndexCode
     * @param cameraIndexCode
     * @return
     */
    @RequestMapping(value = "/selectCameraByIndexCode", method = RequestMethod.POST)
    public ResponseResult selectCameraByIndexCode(@RequestParam String cameraIndexCode){
        return service.selectCameraByIndexCode(cameraIndexCode);
    }

    /**
     * 获取摄像头详情，通过id
     * @param id
     * @return
     */
    @RequestMapping(value = "/selectCameraById", method = RequestMethod.POST)
    public ResponseResult selectCameraById(@RequestParam int id){
        return service.selectCameraById(id);
    }

    /**
     * 获取摄像头详情同时提供萤石云AccessToken
     * @param cameraIndexCode
     * @return
     */
    @RequestMapping(value = "/getCameraByIndexCode", method = RequestMethod.POST)
    public ResponseResult getCameraByIndexCode(@RequestParam String cameraIndexCode){
        return service.getCameraByIndexCode(cameraIndexCode);
    }

    /**
     * 获取摄像头个数
     * @return
     */
    @RequestMapping(value = "/getCameraCount", method = RequestMethod.POST)
    public ResponseResult getCameraCount(){
        return service.getCameraCount();
    }

    /**
     * 查询配置信息不全的摄像头列表
     * @param pageNo
     * @param pageSize
     * @return
     */
    @RequestMapping(value = "/selectNotConfiguredCamera", method = RequestMethod.POST)
    public ResponseResult selectNotConfiguredCamera(@RequestParam int pageNo, @RequestParam int pageSize){
        return service.selectNotConfiguredCamera(pageNo, pageSize);
    }

    /**
     * 编辑摄像头所属工段、专业、值班室
     * @param camera
     * @return
     */
    @NeedRole("管理员")
    @RequestMapping(value = "/updateCamera", method = RequestMethod.POST)
    public ResponseResult updateCamera(Camera camera){
        return service.updateCamera(camera);
    }

    /**
     * 获取九宫格摄像头
     * @param cameraIndexCode
     * @return
     */
    @RequestMapping(value = "/getCameraSquare", method = RequestMethod.POST)
    public ResponseResult getCameraSquare(@RequestParam String cameraIndexCode){
        return service.getCameraSquare(cameraIndexCode);
    }

    /**
     * 通过id获取九宫格摄像头
     * @param id
     * @return
     */
    @RequestMapping(value = "/getCameraSquareById")
    public ResponseResult getCameraSquareById(@RequestParam int id){
        return service.getCameraSquareById(id);
    }

    /**
     * 添加九宫格设置
     * @param cameraSquare
     * @return
     */
    @NeedRole("管理员")
    @RequestMapping(value = "/addCameraSquare", method = RequestMethod.POST)
    @ResponseBody
    public ResponseResult addCameraSquare(CameraSquare cameraSquare){
        return service.addCameraSquare(cameraSquare);
    }

    /**
     * 修改九宫格设置通过cameraIndexCode
     * @param cameraSquare
     * @return
     */
    @NeedRole("管理员")
    @RequestMapping(value = "/updateCameraSquare", method = RequestMethod.POST)
    public ResponseResult updateCameraSquare(CameraSquare cameraSquare){
        return service.updateCameraSquare(cameraSquare);
    }

    /**
     * 修改九宫格设置通过id
     * @param cameraSquare
     * @return
     */
    @NeedRole("管理员")
    @RequestMapping(value = "/updateCameraSquareById", method = RequestMethod.POST)
    public ResponseResult updateCameraSquareById(CameraSquare cameraSquare){
        return service.updateCameraSquareById(cameraSquare);
    }

    /**
     * 删除九宫格设置
     * @param id
     * @return
     */
    @NeedRole("管理员")
    @RequestMapping(value = "/deleteCameraSquare", method = RequestMethod.POST)
    @ResponseBody
    public ResponseResult deleteCameraSquare(@RequestParam("id") int id){
        return service.deleteCameraSquare(id);
    }

    /**
     * 删除摄像头
     * @param id
     * @return
     */
    @NeedRole("管理员")
    @RequestMapping(value = "/deleteCamera", method = RequestMethod.POST)
    @ResponseBody
    public ResponseResult deleteCamera(@RequestParam("id") int id){
        return service.deleteCamera(id);
    }

    /**
     * 分页查询摄像头组集合
     * @param pageNo
     * @param pageSize
     * @摄像头名称关键字 keyword
     * @return
     */
    @RequestMapping(value = "/selectCameraGroups", method = RequestMethod.POST)
    public ResponseResult selectCameraGroups(String keyword, @RequestParam int pageNo, @RequestParam int pageSize){
        return service.selectCameraGroups(keyword, pageNo, pageSize);
    }

    /**
     * 通过id获取摄像头组
     * @param id
     * @return
     */
    @RequestMapping(value = "/getCameraGroupById")
    public ResponseResult getCameraGroupById(@RequestParam int id){
        return service.getCameraGroupById(id);
    }

    /**
     * 添加摄像头组
     * @param cameraGroup
     * @return
     */
    @NeedRole("管理员")
    @RequestMapping(value = "/addCameraGroup", method = RequestMethod.POST)
    @ResponseBody
    public ResponseResult addCameraGroup(CameraGroup cameraGroup){
        return service.addCameraGroup(cameraGroup);
    }

    /**
     * 删除摄像头组
     * @param id
     * @return
     */
    @NeedRole("管理员")
    @RequestMapping(value = "/deleteCameraGroup", method = RequestMethod.POST)
    @ResponseBody
    public ResponseResult deleteCameraGroup(@RequestParam("id") int id){
        return service.deleteCameraGroup(id);
    }

    /**
     * 通过id修改摄像头组设置
     * @param cameraGroup
     * @return
     */
    @NeedRole("管理员")
    @RequestMapping(value = "/updateCameraGroupById", method = RequestMethod.POST)
    public ResponseResult updateCameraGroupById(CameraGroup cameraGroup){
        return service.updateCameraGroupById(cameraGroup);
    }

    //endregion


}
